/* 
 * Copyright (c) 2012, Fromentin Xavier, Schnell Michaël, Dervin Cyrielle, Brabant Quentin
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *      * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *      * The names of its contributors may not be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Fromentin Xavier, Schnell Michaël, Dervin Cyrielle OR Brabant Quentin 
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package kameleon.document;

import java.util.Iterator;

import kameleon.exception.InvalidIndexException;

/**
 * Represents a row in an array.
 * 
 * <p>Standard properties include : none.
 * 
 * @author		Fromentin Xavier, Schnell Michaël, Dervin Cyrielle, Brabant Quentin
 * @version		1.0
 */
public class Row extends ElementProperties implements Iterable<Cell> {

	/**
	 * Needed to serialize this class.
	 * 
	 * @see		java.io.Serializable
	 */
	private static final long serialVersionUID = 3242065006175010059L ;

	/**
	 * Cells contained in this row.
	 */
	protected Cells cells ;

	/**
	 * Builds an instance with no properties.
	 */
	public Row() {
		super() ;
		this.cells = new Cells() ;
	}// Row()

	/**
	 * Add an instance of {@code Cell} at the specified index.
	 * 
	 * @param 	c
	 * 			instance of {@code Cell} added
	 * 
	 * @param 	index
	 * 			insert position
	 * 
	 * @throws	InvalidIndexException
	 * 			if the given index is out of range
	 * 			{@code index < 0 || index >= getCount()}
	 * 
	 * @see		Cells#add(Cell, int)
	 */
	public void add(Cell c, int index) throws InvalidIndexException {
		this.cells.add(c, index) ;
	}// add(Cell, int)

	/**
	 * Prepends an instance of {@code Cell}.
	 * 
	 * @param 	c
	 * 			instance of {@code Cell} prepended
	 * 
	 * @see		Cells#push(Cell)
	 */
	public void push(Cell c) {
		this.cells.push(c) ;
	}// push(Cell)

	/**
	 * Appends an instance of {@code Cell}.
	 * 
	 * @param 	c
	 * 			instance of {@code Cell} appended
	 * 
	 * @see		Cells#append(Cell)
	 */
	public void append(Cell c) {
		this.cells.append(c) ;
	}// append(Cell)

	/**
	 * Removes the instance of {@code Cell} found at the given index.
	 * 
	 * @param 	index
	 * 			index of the removed {@code Cell}
	 * 
	 * @throws	InvalidIndexException
	 * 			if the given index is out of range
	 * 			{@code index < 0 || index >= getCount()}
	 * 
	 * @see		Cells#remove(int)
	 */
	public void remove(int index) throws InvalidIndexException {
		this.cells.remove(index) ;
	}// remove(int)

	/**
	 * Removes all the instances matching the given {@code Cell}.
	 * 
	 * @param 	c
	 * 			removed {@code Cell}
	 * 
	 * @see		Cells#remove(Cell)
	 */
	public void remove(Cell c) {
		this.cells.remove(c) ;
	}// remove(Cell)

	/**
	 * Returns the number of instances of {@code Cell} contained in this instance.
	 * 
	 * @return	Number of instances of {@code Cell} contained in this instance
	 * 
	 * @see		Cells#getCount()
	 */
	public int getCount() {
		return this.cells.getCount() ;
	}// getCount()

	/**
	 * Returns the instance of {@code Cell} contained at the given index.
	 * 
	 * @param 	index
	 * 			index of the requested {@code Cell}
	 * 
	 * @return	the instance of {@code Cell} at the given index
	 * 
	 * @see		Cells#getCell(int)
	 */
	public Cell getCell(int index) {
		return this.cells.getCell(index) ;
	}// getCell()

	/**
	 * Returns an iterator for this instance.
	 * 
	 * <p>The iterator iterates over the cells sequentially.
	 * 
	 * @return	an instance of {@code Iterator<Cell>} for this instance
	 */
	@Override
	public Iterator<Cell> iterator() {
		return this.cells.iterator() ;
	}// iterator()

}// class Row